home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / PDraw3.0.adf / pdraw_rex.lzh / DistributeObjects.pdrx < prev    next >
Text File  |  1992-06-17  |  4KB  |  184 lines

  1. /*
  2. @N
  3.  
  4. This Genie will redistribute the objects in a selection evenly across a specified range. 
  5.  
  6. */
  7. cr = '0a'x
  8. msg = PDSetup.rexx(2,0)
  9. units = getclip(pds_units)
  10. if msg ~= 1 then exit_msg(msg)
  11.  
  12. signal on halt
  13. signal on break_c
  14. signal on break_e
  15. signal on break_d
  16.  
  17. if pdm_NumSelObjs() = 0 then exit_msg("Please select a group of objects first")
  18.  
  19. hspacing = "Left"cr"Right"cr"_Centers"cr"Objects"cr"None"
  20. vspacing = "Top"cr"Bottom"cr"_Centers"cr"Objects"cr"None"
  21.  
  22. hspacing = pdm_SelectFromList("Horizontal Distribution..", 20, 5, 2, hspacing)
  23. if hspacing = '' then exit_msg()
  24.  
  25. vspacing = pdm_SelectFromList("Vertical Distribution..", 20, 5, 2, vspacing)
  26. if vspacing = '' then exit_msg()
  27.  
  28. vdist = 0
  29. hdist = 0
  30.  
  31. grouprect = pdm_GetObjPosn()
  32. groupleft = word(grouprect, 1)
  33. grouptop = word(grouprect, 2)
  34. grouprect = pdm_GetObjSize()
  35. groupwidth = word(grouprect, 1)
  36. groupheight = word(grouprect, 2)
  37. right = groupleft + groupwidth
  38. bottom = grouptop + groupheight
  39.  
  40. if units >2 then do
  41.    groupleft = pdm_ConvertUnits(1, units, groupleft)
  42.    right = pdm_ConvertUnits(1, units, right)
  43.    grouptop = pdm_ConvertUnits(1, units, grouptop)
  44.    bottom = pdm_ConvertUnits(1, units, bottom)
  45. end
  46.  
  47. if hspacing ~= "None" then do
  48.    htext = "From:"groupleft || cr"To:"right
  49.    hdist = pdm_GetForm( "Horizontal Distribution", 8, htext)
  50.    if hdist = '' then exit_msg()
  51.  
  52.    parse var hdist startx '0a'x endx
  53.  
  54.    if ~(datatype(startx, n) & datatype(endx, n)) then
  55.        call exit_msg('Invalid Input')
  56.  
  57.    if units >2 then do
  58.       startx = pdm_ConvertUnits(units, 1, startx)
  59.       endx = pdm_ConvertUnits(units, 1, endx)
  60.    end
  61.  
  62. end
  63.  
  64. if vspacing ~= "None" then do
  65.    vtext = "From:"grouptop || cr"To:"bottom
  66.  
  67.    vdist = pdm_GetForm( "Vertical Distribution", 8, vtext)
  68.    if vdist = '' then exit_msg()
  69.  
  70.    parse var vdist starty '0a'x endy
  71.  
  72.    if ~(datatype(starty, n) & datatype(endy, n)) then
  73.        call exit_msg('Invalid Input')
  74.    
  75.    if units >2 then do
  76.       starty = pdm_ConvertUnits(units, 1, starty)
  77.       endy = pdm_ConvertUnits(units, 1, endy)
  78.    end
  79.  
  80. end
  81.  
  82. counter = 0
  83. obj = pdm_SelFirstObj()
  84.  
  85. sumwidths   = 0
  86. sumheights  = 0
  87.  
  88. do while obj ~= 0
  89.    if ((iscompound(obj) = 0) | (isfirst(obj) = 1)) then do
  90.       counter = counter + 1
  91.       objects.counter = obj
  92.  
  93.       objpos = pdm_GetObjVisPosn(obj)
  94.       objsze = pdm_GetObjVisSize(obj)
  95.       objects.counter.0 = word(objpos, 1) /* left  */
  96.       objects.counter.1 = word(objpos, 2) /* top      */
  97.       objects.counter.2 = word(objsze, 1) /* width */
  98.       objects.counter.3 = word(objsze, 2) /* height   */
  99.  
  100.       sumwidths = sumwidths + objects.counter.2
  101.       sumheights = sumheights + objects.counter.3
  102.    end
  103.    obj = pdm_SelNextObj(obj)
  104.  
  105. end
  106.  
  107. vpos  = starty
  108. hpos  = startx
  109. vmove = "vpos = vpos + vspace"
  110. hmove = "hpos = hpos + hspace"
  111.  
  112. if vspacing = "Top" then do
  113.    vspace = (endy - starty) / max(2,(counter - 1))
  114.    vstring = "vpos"
  115. end
  116. else if vspacing = "Bottom" then do
  117.    vspace = (endy - starty) / max(2,(counter - 1))
  118.    vstring  = "vpos - objects.i.3"
  119. end
  120. else if vspacing = "Centers" then do
  121.    vspace = (endy - starty) / max(2,(counter - 1))
  122.    vstring = "vpos - .5 * objects.i.3"
  123. end
  124. else if vspacing = "Objects" then do
  125.    vdist = ((endy - starty) - sumheights) / max(2,(counter - 1))
  126.    vstring = "vpos"
  127.    vmove = "vpos = vpos + objects.i.3 + vdist"
  128. end
  129. else do
  130.    vstring = "objects.i.1"
  131.    vmove = "/**/"
  132. end
  133.  
  134. if hspacing = "Left" then do
  135.    hspace = (endx - startx) / max(2,(counter - 1))
  136.    hstring = "hpos"
  137. end
  138. else if hspacing = "Right" then do
  139.    hspace = (endx - startx) / max(2,(counter - 1))
  140.    hstring  = "hpos - objects.i.2"
  141. end
  142. else if hspacing = "Centers" then do
  143.    hspace = (endx - startx) / max(2,(counter - 1))
  144.    hstring = "hpos - .5 * objects.i.2"
  145. end
  146. else if hspacing = "Objects" then do
  147.    hdist = ((endx - startx) - sumwidths) / max(2,(counter - 1))
  148.    hstring = "hpos"
  149.    hmove = "hpos = hpos + objects.i.2 + hdist"
  150. end
  151. else do
  152.    hstring = "objects.i.0"
  153.    hmove = "/**/"
  154. end
  155.  
  156. do i = 1 to counter
  157.     
  158.    interpret "x = "hstring
  159.    interpret "y = "vstring
  160.    call pdm_SetObjPosn(objects.i, x, y)
  161.    interpret vmove
  162.    interpret hmove
  163.  
  164. end
  165.  
  166. call exit_msg()
  167. break_d:
  168. break_e:
  169. break_c:
  170. halt:
  171.     call exit_msg("User aborted Genie!")
  172.  
  173. exit_msg: procedure expose units
  174. do
  175.    parse arg message
  176.  
  177.    if message ~= '' then call pdm_Inform( 1, message, )
  178.  
  179.    call pdm_SetUnits(units)
  180.    call pdm_AutoUpdate(1)
  181.    exit
  182.  
  183. end
  184.